<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // var request = new XMLHttpRequest();

    // request.open('get','a.html',true);

    // request.send();
    var request = new XMLHttpRequest();  //新建httprequest 对象
    request.open('GET','a.html',true);  //规定请求类型
    
    /*
    请求发送过程中，request.onreadystatechange 被调用3次，
    request.readyState 依次返回 2,3,4 值 表示不同的请求状态 
     */
    request.onreadystatechange = function() {
    	if(request.readyState == 4){
	    	console.log(request.readyState);
	    	console.log(request.status);

	    	if(request.status == 200) {
	    		var s = request.responseText;
	    		console.log(s);
	    		var data = JSON.parse(s);
	    		console.log(data.username);


	    	}
    	}
    };
    request.send();    //发送请求
    /*
     request.send() 之前必须有 reuqest.open('','',true)规定请求的类型，不能单独使用request.send() 向服务器发起请求
    */

</script>
</body>
</html>